﻿@page "/datagrid"

@using NorthwindBlazor.Data
@using NorthwindBlazor.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inject NorthwindContext dbContext

<h1 style="display:inline">DataGrid</h1><a style="margin-left: 10px" href="https://github.com/akorchev/blazor.radzen.com/blob/master/Pages/DataGridPage.razor" target="_blank">[source code]</a>

<p>This page demonstrates <b>DataGrid</b> component.</p>

@if (employees == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <RadzenGrid AllowFiltering="true" AllowPaging="true" PageSize="5" AllowSorting="true" Data="@employees" TItem="Employee">
        <Columns>
            <RadzenGridColumn TItem="Employee" Property="EmployeeID" Title="Employee ID" />
            <RadzenGridColumn TItem="Employee" Property="Photo" Title="Photo" Sortable="false" Filterable="false">
                <Template Context="data">
                    <RadzenImage Path="@data?.Photo" />
                </Template>
            </RadzenGridColumn>
            <RadzenGridColumn TItem="Employee" Property="LastName" Title="Last Name" />
            <RadzenGridColumn TItem="Employee" Property="FirstName" Title="First Name" />
            <RadzenGridColumn TItem="Employee" Property="Title" Title="Title" />
            <RadzenGridColumn TItem="Employee" Property="TitleOfCourtesy" Title="Title Of Courtesy" />
            <RadzenGridColumn TItem="Employee" Property="BirthDate" Title="Birth Date" Format="date-time">
                <Template Context="data">
                    @String.Format("{0:d}", data.BirthDate)
                </Template>
            </RadzenGridColumn>
            <RadzenGridColumn TItem="Employee" Property="HireDate" Title="Hire Date" Format="date-time">
                <Template Context="data">
                    @String.Format("{0:d}", data.HireDate)
                </Template>
            </RadzenGridColumn>
            <RadzenGridColumn TItem="Employee" Property="Address" Title="Address" />
            <RadzenGridColumn TItem="Employee" Property="City" Title="City" />
            <RadzenGridColumn TItem="Employee" Property="Region" Title="Region" />
            <RadzenGridColumn TItem="Employee" Property="PostalCode" Title="Postal Code" />
            <RadzenGridColumn TItem="Employee" Property="Country" Title="Country" />
            <RadzenGridColumn TItem="Employee" Property="HomePhone" Title="Home Phone" />
            <RadzenGridColumn TItem="Employee" Property="Extension" Title="Extension" />
            <RadzenGridColumn TItem="Employee" Property="Notes" Title="Notes" />
        </Columns>
    </RadzenGrid>
}

@code {
    IEnumerable<Employee> employees;

    protected override async Task OnInitAsync()
    {
        employees = await Task.FromResult(dbContext.Employees);
    }
}
